package com.swust.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.swust.exam.pojo.Question;
import com.swust.exam.service.QuestionService;

@Controller
@RequestMapping(value="/question")
public class QuestionController {
	@Autowired
	private QuestionService questionService;
	
	@RequestMapping(value = "/get")
	public  Question questionGet(int id,Model model){
		return questionService.get(id);
	}
	
	
	@RequestMapping(value="/delete")
	public String questionDelete(int id,Model model,int bankId) {
		questionService.delete(id);
		List<Question> list=questionService.getquestionlist(bankId);
		model.addAttribute("questionlist",list);
		return "questionlist";
	}
	
	@RequestMapping(value="/insert")
	public String questionInsert(Question question,Model model) {
		questionService.insert(question);
		List<Question> list=questionService.getquestionlist(question.getBankId());
		model.addAttribute("questionlist",list);
		return "questionlist";
	}
	
	@RequestMapping(value="/update")
	public String questionUpdate(Question question, Model model) {
		questionService.update(question);
		return "introduce";
	}
		
	@RequestMapping(value="/questionlist")
	public String questionlist(int bankId,Model model) {
		List<Question> list=questionService.getquestionlist(bankId);
		model.addAttribute("questionlist",list);
		return "questionlist";
	}

}
